<template>
  <div class="app-container">

    <el-form ref="form" label-width="140px">
      <el-row :gutter="100">
        <el-col :span="12">

          <div class="tit">
            <em>*</em> 开放时间
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleLang(1)">多语言配置</el-button>
              <el-button type="primary" size="mini" @click="handleAdd">保存</el-button>
            </div>
          </div>
          <el-form-item label="开馆时间">
            <el-checkbox-group v-model="form.date">
              <el-checkbox label="1">周一</el-checkbox>
              <el-checkbox label="2">周二</el-checkbox>
              <el-checkbox label="3">周三</el-checkbox>
              <el-checkbox label="4">周四</el-checkbox>
              <el-checkbox label="5">周五</el-checkbox>
              <el-checkbox label="6">周六</el-checkbox>
              <el-checkbox label="7">周日</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="每日开馆时间">
            <el-time-picker
              is-range
              v-model="form.time"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="每日停止入场时间">
            <el-time-picker
              is-range
              v-model="form.time"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="备注" prop="noticeType">
            <el-input type="textarea" :rows="3" v-model="form.memo" placeholder="请输入" />
          </el-form-item>


          <div class="tit">
            <em>*</em> 公共交通
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleLang(1)">多语言配置</el-button>
              <el-button type="primary" size="mini" @click="handleAdd">保存</el-button>
            </div>
          </div>
          <el-input style="margin-top: 10px;" type="textarea" :rows="5" v-model="form.memo" placeholder="请输入" />

          <div class="tit" style="margin-top:30px;">
            <em>*</em> 车辆停泊
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleAdd">添加停车场</el-button>
            </div>
          </div>
          <el-table v-loading="loading" :data="noticeList">
            <el-table-column label="停车场地址" align="center" prop="createBy" />
            <el-table-column label="开放时间" align="center" prop="createBy" />
            <el-table-column label="收费标准" align="center" prop="createBy" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <span @click="handleDelete(scope.row)" class="red">删除</span>
                <span @click="handleUpdate(scope.row)" class="sanm">编辑</span>
              </template>
            </el-table-column>
          </el-table>

        </el-col>

        <el-col :span="12">

          <div class="tit">
            <em>*</em> 参观须知
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleLang(1)">多语言配置</el-button>
              <el-button type="primary" size="mini" @click="handleAdd">保存</el-button>
            </div>
          </div>
          <el-form-item label="参观须知" prop="noticeType">
            <el-input type="textarea" :rows="5" v-model="form.memo" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="特别提醒" prop="noticeType">
            <el-input type="textarea" :rows="5" v-model="form.memo" placeholder="请输入" />
          </el-form-item>

          <div class="tit">
            <em>*</em> 联系我们
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleLang(1)">多语言配置</el-button>
              <el-button type="primary" size="mini" @click="handleAdd">保存</el-button>
            </div>
          </div>
          <el-form-item label="电话" prop="noticeType">
            <el-select style="width: 100px;" v-model="form.noticeType" placeholder="请选择">
              <el-option
                v-for="dict in dict.type.sys_notice_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
            <el-input style="width: 200px;" v-model="form.memo" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="邮箱" prop="noticeType">
            <el-input v-model="form.memo" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="地址" prop="noticeType">
            <el-input type="textarea" :rows="3" v-model="form.memo" placeholder="请输入" />
          </el-form-item>

          <div class="tit">
            <em>*</em> 导览地图
            <div style="float:right;">
              <el-button type="primary" size="mini" @click="handleAdd">添加地图</el-button>
            </div>
          </div>
          <el-table v-loading="loading" :data="noticeList">
            <el-table-column label="导览地图" align="center" prop="createBy" />
            <el-table-column label="楼层名称" align="center" prop="createBy" />
            <el-table-column label="实际楼层" align="center" prop="createBy" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <span @click="handleDelete(scope.row)" class="red">删除</span>
                <span @click="handleUpdate(scope.row)" class="sanm">编辑</span>
              </template>
            </el-table-column>
          </el-table>

        </el-col>

      </el-row>
    </el-form>


  </div>
</template>

<script>
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";

export default {
  name: "Notice",
  dicts: ['sys_notice_status', 'sys_notice_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {
        date: []
      },
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ]
      },
      daterangeCreateTime: [],

      viewOpen: false,

      //多语言设置
      langOpen: false,
      langTit: '多语言配置',
      //type 1输入框 2图片上传 3富文本
      langDicts: [
        {id: 2, name: '名称', status: 0, flag: 1, type: 1, val: 'http://www.baidu.com'}
      ],
      setCur: {},
      setOpen: false,
      langs: [
        {id: 1, name: '中文（简体）', val: ''},
        {id: 2, name: '中文（繁体）', val: ''},
        {id: 3, name: '英语（English）', val: ''}
      ]

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listNotice(this.queryParams).then(response => {
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleLang(row){
      this.langTit = '藏品' + ' - 多语言配置';
      this.langOpen = true;
    },
    handleSet(row){
      this.setCur = row;
      this.setOpen = true;
    },
    setSubmit(){
      addNotice(this.form).then(response => {
        this.$modal.msgSuccess("设置成功");
        this.setOpen = false;
        this.getList();
      });
    },
    setCancel(){
      this.setOpen = false;
    },
    handleView(row){
      this.form = row;
      this.viewOpen = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增藏品类型";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "编辑藏品类型";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.noticeId != undefined) {
            updateNotice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNotice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const noticeIds = row.noticeId || this.ids
      this.$modal.confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项？').then(function() {
        return delNotice(noticeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 覆盖默认的上传行为
    requestUpload() {
    },
    // 向左旋转
    rotateLeft() {
      this.$refs.cropper.rotateLeft();
    },
    // 向右旋转
    rotateRight() {
      this.$refs.cropper.rotateRight();
    },
    // 图片缩放
    changeScale(num) {
      num = num || 1;
      this.$refs.cropper.changeScale(num);
    },
    // 上传预处理
    beforeUpload(file) {
      if (file.type.indexOf("image/") == -1) {
        this.$modal.msgError("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");
      } else {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => {
          this.options.img = reader.result;
          this.options.filename = file.name;
        };
      }
    },
    // 上传图片
    uploadImg() {
      this.$refs.cropper.getCropBlob(data => {
        let formData = new FormData();
        console.log(this.options.filename)
        formData.append("avatarfile", data, this.options.filename);
        uploadAvatar(formData).then(response => {
          this.open = false;
          this.options.img = response.data.imgUrl;
          store.commit('SET_AVATAR', this.options.img);
          this.$modal.msgSuccess("修改成功");
          this.visible = false;
        });
      });
    }
  }
};
</script>
<style>
  .tit{ margin-bottom:20px; }
</style>